<?php
	ob_start();
	session_start();

	function __autoload($class_name) {
	include './'.$class_name . '.php';
	}
	
	function test_input($data) {
		$data = trim($data);
		$data = stripslashes($data);
		$data = htmlspecialchars($data);
		return $data;
	}
	
	$dbConfig = new DBConfigNew(); 
	$conn = $dbConfig->getConnection();
	$mysqli=$conn;
	$result = array();
	$status = true;	
	$fname = null;
	$contact = null;
	$lname = null;
	$email = null;
	$projectId = null;
	$stmt = null;
	$query = "CALL pyramid.contact_project_i(?,?,?,?,?);";
	
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		if (isset($_POST["fname"])){
			$fname = test_input($_POST["fname"]);		
		}
		if (isset($_POST["lname"])){
			$lname = test_input($_POST["lname"]);		
		}
		if (isset($_POST["contact"])){
			$contact = test_input($_POST["contact"]);		
		}
		if (isset($_POST["email"])){
			$email = test_input($_POST["email"]);		
		}
		if (isset($_POST["projectId"])){
			$projectId = test_input($_POST["projectId"]);		
		}
	}
	if ($fname == null || $fname == "" || $contact == null || $contact == "" ||
			$lname == null || $lname == "" || $email == null || $email == "" || $projectId == null || $projectId == ""){	
		$status = false;
	}
	
	$stmt = $mysqli->prepare($query);
	$stmt->bind_param("ssssi", $fname, $lname, $email, $contact, $projectId); 
	
	
	if($status && !$stmt->execute()){
		$status = false;
	}
	
	$results['success'] = $status;
	echo json_encode($results);
	
	ob_end_flush();
?>